//
//  AppDelegate.m
//  project_delicious
//
//  Created by dlios on 15-3-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import <ShareSDK/ShareSDK.h>


#import "WeiboApi.h"
#import "WeiboSDK.h"

//首页
#import "MainViewController.h"
//"我的"页面
#import "OwnViewController.h"
//推荐
#import "RecommendViewController.h"
//发现
#import "DiscoverViewController.h"
//第三方颜色方法
#import "UIColor+AddColor.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

//判断网络
- (NSString *)GetCurrntNet
{
    NSString *result;
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    switch ([reach currentReachabilityStatus]) {
        case NotReachable:
            return nil;
            break;
        case ReachableViaWWAN://使用3G网络
            result = @"3G";
            break;
        case ReachableViaWiFi://wifi
            result = @"WIFI";
            break;
        default:
            break;
    }
    return result;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    
    [ShareSDK registerApp:@"api20"];
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"3241463081"
                               appSecret:@"02b78366ddf723a458722992e779d2ce"
                             redirectUri:@"http://aa.com"];
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
    [ShareSDK  connectSinaWeiboWithAppKey:@"3241463081"
                                appSecret:@"02b78366ddf723a458722992e779d2ce"
                              redirectUri:@"http://aa.com"
                              weiboSDKCls:[WeiboSDK class]];
    
    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
    [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                  appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                redirectUri:@"http://www.sharesdk.cn"
                                   wbApiCls:[WeiboApi class]];
//    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
//    [ShareSDK connectQZoneWithAppKey:@"100371282"
//                           appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
//                   qqApiInterfaceCls:[QQApiInterface class]
//                     tencentOAuthCls:[TencentOAuth class]];
//    
//    //添加QQ应用  注册网址  http://open.qq.com/
//    [ShareSDK connectQQWithQZoneAppKey:@"100371282"
//                     qqApiInterfaceCls:[QQApiInterface class]
//                       tencentOAuthCls:[TencentOAuth class]];

//    //添加微信应用 注册网址 http://open.weixin.qq.com
//    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
//                           wechatCls:[WXApi class]];
//    
//    //添加搜狐微博应用  注册网址  http://open.t.sohu.com
//    [ShareSDK connectSohuWeiboWithConsumerKey:@"SAfmTG1blxZY3HztESWx"
//                               consumerSecret:@"yfTZf)!rVwh*3dqQuVJVsUL37!F)!yS9S!Orcsij"
//                                  redirectUri:@"http://www.sharesdk.cn"];

    
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    //改变标签栏(tabBar)的颜色
    //tabBar.tabBar.barTintColor = [UIColor colorFromHexCode:@"feeeed"];
    //选中标签的时候, 标签的颜色
    tabBar.tabBar.tintColor = [UIColor colorFromHexCode:@"ffc20e"];
    
    // 首页
    MainViewController *main = [[MainViewController alloc] init];
    main.title = @"首页";
    main.tabBarItem.image = [UIImage imageNamed:@"MainTabBar.png"];
    //每一个tabBar标签页都是由UINavigation控制, 可以自己选择需要不需要
    UINavigationController *naviMain = [[UINavigationController alloc] initWithRootViewController:main];
    
    //我的
    OwnViewController *own = [[OwnViewController alloc] init];
    own.title = @"我的";
    own.tabBarItem.image = [UIImage imageNamed:@"OwnTabBar.png"];
    //UINavigation
    UINavigationController *naviOwn = [[UINavigationController alloc] initWithRootViewController:own];
    
    //推荐
    RecommendViewController *recommend = [[RecommendViewController alloc] init];
    recommend.title = @"推荐";
    recommend.tabBarItem.image = [UIImage imageNamed:@"RecommendTabBar.png"];
    //UINavigation
    UINavigationController *naviRecommend = [[UINavigationController alloc] initWithRootViewController:recommend];
    
    //发现
    DiscoverViewController *discover = [[DiscoverViewController alloc] init];
    discover.title = @"发现";
    discover.tabBarItem.image = [UIImage imageNamed:@"DiscoverTabBar.png"];
    //UINavigation
    UINavigationController *naviDiscover = [[UINavigationController alloc]initWithRootViewController:discover];
    
    //创建一个viewController的数组, 给tabBar的属性赋值
    tabBar.viewControllers = @[naviMain, naviRecommend, naviDiscover, naviOwn];
    self.window.rootViewController = tabBar;
    
    [main release];
    [naviMain release];
    
    [recommend release];
    [naviRecommend release];
    
    [discover release];
    [naviDiscover release];
    
    [own release];
    [naviOwn release];
    
    [tabBar release];
    
    return YES;
}


- (void)dealloc
{
    [_window release];
    [super dealloc];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
